<template>
  <div style="overflow: auto">
    <!--<el-tabs v-model="activeTab" type="card" @tab-click="handleClick">
      <el-tab-pane v-for="item in projects"   :key="item.DSSL_ProjectID" :label="item.DSSP_Name" :name="item.DSSL_ProjectID"></el-tab-pane>
    </el-tabs>-->
    <div class="header">
        <el-form inline style="margin-top: 20px">
          <el-form-item label="项目">
            <el-select style="width: 400px;" v-model="selectProject" filterable placeholder="请选择" @change="handleClick">
              <el-option
                
                v-for="item in projects"
                :key="item.DSSL_ProjectID"
                :label="item.DSSP_Name"
                :value="item.DSSL_ProjectID">
              </el-option>
            </el-select>


          </el-form-item>
          <el-button type="primary" @click="doGetLogByUser">
            提交日志
          </el-button>
        </el-form>
        <el-form inline style="margin-top: 20px">
          <el-form-item label="姓名">
            <el-input v-model="searchName"></el-input>
          </el-form-item>
          <el-form-item label="勘察次数">
            <el-select v-model="searchCount" placeholder="请选择">
              <el-option
                :key="1" label="全部":value="0">
              </el-option>
              <el-option
                :key="1" label="首勘":value="1">
              </el-option>
              <el-option
                :key="2" label="复勘":value="2">
              </el-option>
              <el-option
                :key="3" label="二次复勘":value="3">
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="勘察人员">
            <el-select style="width: 300px" v-model="selectEmpId" filterable remote reserve-keyword placeholder="请输入关键词"
              :remote-method="doGetEmployees" :loading="loading">
              <el-option label="全部" :value="0">
                全部
              </el-option>
              <el-option v-for="item in employees" :key="item.ECV_TargetID" :label="item.USR_Name"
                :value="item.EMP_ID">
                {{ item.USR_Name }}
              </el-option>
            </el-select>
          </el-form-item>
          <el-button @click="doGetSurveys()">搜索</el-button>
        </el-form>
      </div>

    <div class="container">
      <el-table :data="surveys">
        <el-table-column label="编号" prop="DSSV_No"></el-table-column>
        <el-table-column label="姓名" prop="DSSV_Name"></el-table-column>
        <el-table-column label="村组" prop="DSSV_Village"></el-table-column>
        <el-table-column label="楼层" prop="DSSV_Floor"></el-table-column>
        <el-table-column label="结构类型" prop="DSSV_Structure"></el-table-column>
        <el-table-column label="距离范围" prop="DSSV_Distance"></el-table-column>
        <el-table-column width="100" label="项目阶段">
          <template slot-scope="scope">
            <span>
              {{ surveyStep[scope.row.DSSLM_SurveyCount] }}
            </span>
          </template>
        </el-table-column>

        <el-table-column width="100" label="勘察人员">
          <template slot-scope="scope">
            <span>
              {{
                scope.row.USR_Name == null ? '未勘察' : scope.row.USR_Name
              }}
            </span>
          </template>
        </el-table-column>

        <el-table-column label="定损金额" prop="DSSV_ConfirmMoney"></el-table-column>
        <el-table-column label="报告日期" prop="DSSV_ReportDate">
          <template slot-scope="scope">
            <span>
              {{
                scope.row.DSSV_ReportDate == null
                  ? '未确定'
                  : scope.row.DSSV_ReportDate.split(' ')[0]
              }}
            </span>
          </template>
        </el-table-column>
        <el-table-column label="支付金额" prop="DSSV_PayMoney"></el-table-column>
        <el-table-column label="更新日期" prop="DSSV_UpdateDate">
          <template slot-scope="scope">
            <span>
              {{
                scope.row.DSSV_UpdateDate == null
                  ? '未确定'
                  : scope.row.DSSV_UpdateDate.split(' ')[0]
              }}
            </span>
          </template>
        </el-table-column>
        <el-table-column width="180" label="操作">
          <template slot-scope="scope">
            <el-button type="primary" icon="el-icon-edit" circle @click="toDetailPage(scope.row)"></el-button>
            <el-button type="primary" icon="el-icon-s-check" circle
              @click="toSurveyAudit(scope.row.DSSV_ID)"></el-button>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination :current-page.sync="pageIndex" :total="total" :page-size.sync="pageSize" :page-sizes="[10, 20]"
        @size-change="
          (val) => {
            pageSize = val
            doGetSurveys()
          }
        " @current-change="doGetSurveys()" />
    </div>
    <el-dialog title="审核情况" :visible.sync="auditVis">
      <el-steps align-center>
        <el-step :status="auditInfo.infoAudit ? 'success' : 'process'" title="定位信息">
          <template slot="description">
            <div style="margin-top: 10px" v-for="info in auditInfo.infoAuditList" :key="info">
              {{ info.DSSA_CreateDate.split(' ')[0] }}{{ info.USR_Name }}:{{
                info.DSSA_Remark
              }}
            </div>
          </template>
        </el-step>

        <el-step :status="auditInfo.plantAudit ? 'success' : 'process'" title="户型图">
          <template slot="description">
            <div style="margin-top: 10px" v-for="info in auditInfo.plantAuditList" :key="info">
              {{ info.DSSA_CreateDate.split(' ')[0] }}{{ info.USR_Name }}:{{
                info.DSSA_Remark
              }}
            </div>
          </template>
        </el-step>

        <el-step :status="auditInfo.surveyAudit ? 'success' : 'process'" title="勘查信息">
          <template slot="description">
            <div style="margin-top: 10px" v-for="info in auditInfo.surveyAuditList" :key="info">
              {{ info.DSSA_CreateDate.split(' ')[0] }}{{ info.USR_Name }}:{{
                info.DSSA_Remark
              }}
            </div>
          </template>
        </el-step>
      </el-steps>

      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="auditVis = false">确定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { mapGetters } from 'vuex'
import { baseURL } from '@/config'
import { GetSurveyProjectsByUser, GetSurveyListPageByUser, GetSurveyListByUser, GetSurveyAudits, GetLogByUser } from '@/api/project/survey.js'
import { getEmployees } from '@/api/flowCenter/field/employeeSelection'
export default {
  components: {},
  computed: {
    ...mapGetters({
      curEmp: 'user/curEmp',
    }),
  },
  data: function () {
    return {
      searchName: null,
      total: 0,
      pageIndex: 1,
      pageSize: 10,
      surveys: [],

      addProjectVis: false,
      addOpUserVis: false,
      bigdataVisible: false,

      bigDataPhonePath: '',
      bigDataPath: '',

      addProject: {},
      isEdit: false,
      employees: [],
      loading: false,
      selectEmpId: 0,
      selectEmps: [],
      auditVis: false,
      auditInfo: {},

      activeTab: 0,
      projects: null,

      searchCount: 0,
      selectProject: 0,
      surveyStep: {
        0: '首勘',
        1: '复勘',
        2: '二次复勘',
      },
      stepName: {
        1: '施工前',
        2: '施工中',
        3: '施工后',
      },
      projectInfo:null
    }
  },
  methods: {
    doGetEmployees(val) {
      getEmployees({
        cmpId: this.curEmp.EMP_CmpId,
        keyword: val,
      }).then(({ data }) => {
        this.employees = data
        this.loading = false
      })
    },
    toSurveyAudit(id) {
      this.GetSurveyAudits(id)
    },
    GetProjectByUser(id) {
      var that = this

      GetSurveyProjectsByUser().then((r) => {
        that.projects = r.data
        if (r.data.length > 0) {
          that.selectProject = r.data[0].DSSL_ProjectID
          that.projectInfo = r.data[0]
          that.doGetSurveys()
          /*if(that.projectInfo.DSSV_HasBefore){
            that.selectProjectStep=1
          }else if(that.projectInfo.DSSV_HasAfoot){
            that.selectProjectStep=2
          }else if(that.projectInfo.DSSV_HasAfter){
            that.selectProjectStep=3
          }
          
          console.log(that.projectInfo)*/
        }

      })
    },
    GetSurveyAudits(id) {
      var that = this

      GetSurveyAudits(id).then((r) => {
        console.log(r)
        that.auditInfo = r.data
        that.$nextTick(() => {
          that.auditVis = true
        })
      })
    },
    toDetailPage(row) {
      this.$router.push({
        path: 'userSurveyDetail',
        query: { id: row.DSSV_ID, prjId: row.DSSV_ProjectID },
      })
    },
    toShowPage(row) {
      this.bigDataPath =
        baseURL + '/show/survey.html?prjId=' + row.DSSP_ID + '&stepId=1'
      this.bigDataPhonePath =
        baseURL + '/show/survey/msurvey.html?prjId=' + row.DSSP_ID + '&stepId=1'

      this.bigdataVisible = true
      //window.open(path)
    },
    handleClick() {
      this.searchName = null
      this.searchCount = 0
      this.doGetSurveys()
    },
    doGetLogByUser() {
      var that = this
      var nowDate = new Date().getFullYear() + '-' + (new Date().getMonth() + 1) + '-' + new Date().getDate()
      GetLogByUser(this.selectProject,this.projectInfo.DSSL_StepID).then((r) => {
        var log = {
          'DSUSL_ProjectID':this.selectProject,
          'DSUSL_SurveyCount':r.data.LogDayCount,
          'DSUSL_StepID':this.projectInfo.DSSL_StepID

        }
        var formData = {
          dpmId: 32,
          submitFunc: {
            url: '/api/Project/SurveyStatistics/AddSurverUserLog',
            method: 'post',
            data:log 
          },
          fieldValues: {
            //'ebe81bc6cad68bb3':`{\"time\":\"${nowDate}\",\"displayName\":\"${nowDate}\"}`,//调查时间 
            'WorkDate':`{\"timerange\":[\"${r.data.StartDate}\",\"${r.data.EndDate}\"],\"time1\":\"${r.data.StartDate}\",\"time2\":\"${r.data.EndDate}\",\"displayName\":\"${r.data.StartDate}至${r.data.EndDate}\"}`,//作业时间
            'WorkContent':`{\"text\":\"${that.stepName[this.projectInfo.DSSL_StepID]}入户定位勘查\",\"displayName\":\"${that.stepName[this.projectInfo.DSSL_StepID]}入户定位勘查\"}`,//作业内容
            'CaseID':`{\"id\":${r.data.CaseID},\"displayName\":\"${r.data.CaseID}\"} `,
            'LogAllCount':`{\"num\":${r.data.LogAllCount},\"displayName\":\"${r.data.LogAllCount}\"} `,//总量
            'LogDayCount':`{\"num\":${r.data.LogDayCount},\"displayName\":\"${r.data.LogDayCount}\"} `,//当天
            'LogDoneList':`{\"surveys\":${JSON.stringify(r.data.LogDoneList)}}`,//农户列表
            //'c41cab97e0996ff4':`{\"num\":${r.data.LogImgCount},\"displayName\":\"${r.data.LogImgCount}\"} `,//相片
            'LogDoneCount':`{\"num\":${r.data.LogDoneCount},\"displayName\":\"${r.data.LogDoneCount}\"} `,//累计
            'Days':`{\"num\":${r.data.Days},\"displayName\":\"${r.data.Days}\"} `,//累计天数
            'IsSign':`{\"value\":${r.data.IsSign},\"displayName\":\"是否签到\"} `,//是否签到
            //'5aafbdc34498497c':`{\"timerange\":[\"${r.data.TodayStartTime}\",\"${r.data.TodayEndTime}\"],\"time1\":\"${r.data.TodayStartTime}\",\"time2\":\"${r.data.TodayEndTime}\",\"displayName\":\"${r.data.TodayStartTime}至${r.data.TodayEndTime}\"}`,//当天作业时间
            'SignList':`{\"signLogs\":${JSON.stringify(r.data.SignList)}}`,//签到列表
          }
        }
        //console.log(JSON.stringify(r.data.LogDoneList))
        sessionStorage.setItem('formData', JSON.stringify(formData));
        this.$router.push({
          name: 'formInfoPage',
          query: { flowId: 28 },
        })
      })
    },
    testFunc() {
      console.log(123)
    },
    doGetSurveys() {
      var that = this
      console.log(this.selectEmpId)
      GetSurveyListPageByUser(this.selectProject, this.searchCount, this.selectEmpId, this.pageIndex, this.pageSize, this.searchName).then((r) => {
        that.surveys = r.data.datas
        that.total = r.data.total
      })
    },
  },
  mounted: function () {
    this.GetProjectByUser()

  },
}
</script>

<style scoped>
.header {
  padding: 20px;
}

.container {
  padding: 20px 10px;
}

.upload {
  margin-right: 15px;
}
</style>
